package cn.iocoder.yudao.module.team.service.ordepayment;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.team.controller.admin.ordepayment.vo.*;
import cn.iocoder.yudao.module.team.dal.dataobject.ordepayment.OrdePaymentDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.team.dal.mysql.ordepayment.OrdePaymentMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.team.enums.ErrorCodeConstants.*;

/**
 * 团款项目 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class OrdePaymentServiceImpl implements OrdePaymentService {

    @Resource
    private OrdePaymentMapper ordePaymentMapper;

    @Override
    public Integer createOrdePayment(OrdePaymentSaveReqVO createReqVO) {
        // 插入
        OrdePaymentDO ordePayment = BeanUtils.toBean(createReqVO, OrdePaymentDO.class);
        ordePaymentMapper.insert(ordePayment);

        // 返回
        return ordePayment.getId();
    }

    @Override
    public void updateOrdePayment(OrdePaymentSaveReqVO updateReqVO) {
        // 校验存在
        validateOrdePaymentExists(updateReqVO.getId());
        // 更新
        OrdePaymentDO updateObj = BeanUtils.toBean(updateReqVO, OrdePaymentDO.class);
        ordePaymentMapper.updateById(updateObj);
    }

    @Override
    public void deleteOrdePayment(Integer id) {
        // 校验存在
        validateOrdePaymentExists(id);
        // 删除
        ordePaymentMapper.deleteById(id);
    }

    @Override
        public void deleteOrdePaymentListByIds(List<Integer> ids) {
        // 删除
          ordePaymentMapper.deleteByIds(ids);
        }


    private void validateOrdePaymentExists(Integer id) {
        if (ordePaymentMapper.selectById(id) == null) {
            throw exception(ORDE_PAYMENT_NOT_EXISTS);
        }
    }

    @Override
    public OrdePaymentDO getOrdePayment(Integer id) {
        return ordePaymentMapper.selectById(id);
    }

    @Override
    public PageResult<OrdePaymentDO> getOrdePaymentPage(OrdePaymentPageReqVO pageReqVO) {
        return ordePaymentMapper.selectPage(pageReqVO);
    }
    //批量添加，先删除后添加
    @Override
    public void createBatchOrdePayment(List<OrdePaymentDO> createReqVO) {
        ordePaymentMapper.insertOrUpdate(createReqVO);
    }

}